//
//  CommonView.m
//  Dispatch
//
//  Created by hyeyeon on 14. 2. 14..
//  Copyright (c) 2014년 hyeyeon. All rights reserved.
//

#import "CommonView.h"

@implementation CommonView
@synthesize titleView, backButton, titleLabel, delegate, bodyView, subTitleView, subIcon, subTitleLabel;

- (id)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        // Initialization code
        self.frame = frame;
        [self makeCommenViewObject:(CGRect)frame];
    }
    return self;
}

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
    // Drawing code
}
*/

-(void)makeCommenViewObject:(CGRect)frame{
    
    NSLog(@"makeObject");
    titleView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, frame.size.width, 44)];
    titleView.backgroundColor = ColorFromRGB(0xe9e9e9);
    [self addSubview:titleView];
    
    
    backButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 0, 37, 44)];
    [backButton setImage:[UIImage imageNamed:@"btn_back02"] forState:UIControlStateNormal];
    [titleView addSubview:backButton];
    
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, titleView.frame.size.width, titleView.frame.size.height)];
    titleLabel.backgroundColor = [UIColor clearColor];
    titleLabel.textAlignment = NSTextAlignmentCenter;
    titleLabel.font = [UIFont boldSystemFontOfSize:20];
    titleLabel.textColor = ColorFromRGB(0x2a2829);
    [titleView addSubview:titleLabel];
    
    bodyView = [[UIView alloc] initWithFrame:CGRectMake(0, titleView.frame.origin.y+titleView.frame.size.height, frame.size.width, frame.size.height-titleView.frame.origin.y-titleView.frame.size.height)];
    [self addSubview:bodyView];
}

-(void)makeSubTitleView{
    
    subTitleView = [[UIView alloc] initWithFrame:CGRectMake(0, titleView.frame.origin.y+titleView.frame.size.height, mySize.width, 30)];
    subTitleView.backgroundColor = ColorFromRGB(0x615c65);
    [self addSubview:subTitleView];
    
    bodyView.frame = CGRectMake(0, subTitleView.frame.origin.y+subTitleView.frame.size.height, bodyView.frame.size.width, self.frame.size.height-titleView.frame.size.height-subTitleView.frame.size.height);
    
    subIcon = [[UIImageView alloc] initWithFrame:CGRectMake(10, 0, 19, 30)];
    [subTitleView addSubview:subIcon];
    
    subTitleLabel = [[UILabel alloc] initWithFrame:CGRectMake(subIcon.frame.origin.x+subIcon.frame.size.width+3, 0, 200, subTitleView.frame.size.height)]; //너비는 대강..
    subTitleLabel.backgroundColor = [UIColor clearColor];
    subTitleLabel.textColor = ColorFromRGB(0xffffff);
    subTitleLabel.font = [UIFont systemFontOfSize:13];
    [subTitleView addSubview:subTitleLabel];
}

-(void)setSubTitleIcond:(UIImage*)icon andTitle:(NSString*)title{
    
    if (!subTitleView) {
        [self makeSubTitleView];
    }
    subIcon.image = icon;
    subTitleLabel.text = title;
}

@end
